home *** CD-ROM | disk | FTP | other *** search
- /*
- Att v1.0 ■ (c) 1989 Tony Tortorelli
-
- Usage:
- Att [d:][path][+-hsra /d] filename
-
- h Hidden s System
- r Read Only a Archive
- /d Include directories")
- */
-
- #include <stdio.h>
- #include <errno.h>
- #include <conio.h>
- #include <string.h>
- #include <process.h>
- #include <dir.h>
- #include <dos.h>
- #include <io.h>
-
- void help(void);
-
- void main(int argc, char *argv[])
- {
- char c,directory='n',change='n';
- char dir[MAXDIR],path[MAXPATH],file[MAXPATH];
- char oldatt[5],newatt[5];
- int i,flag=-1,OldAttribute,NewAttribute,set=0,reset=0;
- struct ffblk ffblk;
-
- directvideo=0; /* Use BIOS */
- if(_osmajor < 2){
- fputs("\a\n\t*** Requires DOS 2.0 or greater ***",stderr);
- exit(0);
- }
- if(argc<2)
- help();
- else{
- file[0]=NULL;
- while(--argc>0){
- ++argv;
- if((c=**argv)=='+'){ /* Set Flag */
- change='y';
- while((c=(*(++(*argv))))!=NULL){
- switch(c){
- case 'h':
- case 'H':
- set |= FA_HIDDEN;
- break;
- case 's':
- case 'S':
- set |= FA_SYSTEM;
- break;
- case 'r':
- case 'R':
- set |= FA_RDONLY;
- break;
- case 'a':
- case 'A':
- set |= FA_ARCH;
- break;
- }
- }
- }
- else if(c=='-'){ /* Reset Flag */
- change='y';
- while((c=(*(++(*argv))))!=NULL){
- switch(c){
- case 'h':
- case 'H':
- reset |= FA_HIDDEN;
- break;
- case 's':
- case 'S':
- reset |= FA_SYSTEM;
- break;
- case 'r':
- case 'R':
- reset |= FA_RDONLY;
- break;
- case 'a':
- case 'A':
- reset |= FA_ARCH;
- break;
- }
- }
- }
- else if(c=='/'){ /* Directory option and help */
- while((c=(*(++(*argv))))!=NULL){
- switch(c){
- case '?':
- help();
- break;
- case 'd':
- case 'D':
- directory='y';
- break;
- default:
- help();
- break;
- }
- }
- } /* Find first file, or quit */
- else{
- if((flag=findfirst(*argv,&ffblk,FA_SYSTEM | FA_HIDDEN | FA_RDONLY | FA_ARCH | FA_DIREC)) == -1){
- fprintf(stderr,"\"%s\" not found",strlwr(*argv));
- exit(0);
- }
- fnsplit(*argv,dir,path,file,NULL);
- }
- } /* End of while */
- } /* End of else */
- if(file[0] == NULL) /* If no file entered, quit */
- help();
- if(change == 'y'){ /* heading for changes */
- cputs("\r\nFilename Old New");
- cputs("\r\n──────────── ───── ─────\r\n");
- }
- else{ /* heading for viewing only */
- cputs("\r\nFilename Att");
- cputs("\r\n──────────── ─────\r\n");
- }
- while(!flag){
- if(ffblk.ff_name[0] == '.' || directory == 'n' && (ffblk.ff_attrib & FA_DIREC)){
- flag=findnext(&ffblk); /* Skip '.', and directory (if /d not set) */
- continue;
- }
- fnmerge(file,dir,path,ffblk.ff_name,NULL);
- OldAttribute = _chmod(file,0); /* Find old attribute */
- NewAttribute = OldAttribute; /* copy to new attribute */
- NewAttribute |= set; /* OR 'set' flags */
- NewAttribute &= ~reset; /* AND reset flags */
- i=0; /* store old attributes */
- (ffblk.ff_attrib & FA_SYSTEM) ? (oldatt[i++] = 's') : (oldatt[i++] = '─');
- (ffblk.ff_attrib & FA_HIDDEN) ? (oldatt[i++] = 'h') : (oldatt[i++] = '─');
- (ffblk.ff_attrib & FA_RDONLY) ? (oldatt[i++] = 'r') : (oldatt[i++] = '─');
- (ffblk.ff_attrib & FA_ARCH) ? (oldatt[i++] = 'a') : (oldatt[i++] = '─');
- (ffblk.ff_attrib & FA_DIREC) ? (oldatt[i++] = 'd') : (oldatt[i++] = '─');
- oldatt[i] = NULL;
- if(change == 'y'){ /* only enter loop if set or reset requested */
- i=0; /* store old attributes */
- (NewAttribute & FA_SYSTEM) ? (newatt[i++] = 's') : (newatt[i++] = '─');
- (NewAttribute & FA_HIDDEN) ? (newatt[i++] = 'h') : (newatt[i++] = '─');
- (NewAttribute & FA_RDONLY) ? (newatt[i++] = 'r') : (newatt[i++] = '─');
- (NewAttribute & FA_ARCH) ? (newatt[i++] = 'a') : (newatt[i++] = '─');
- (NewAttribute & FA_DIREC) ? (newatt[i++] = 'd') : (newatt[i++] = '─');
- newatt[i] = NULL;
- if(NewAttribute != OldAttribute){ /* change only if new attribute is different */
- if((_chmod(file,1,(NewAttribute & ~FA_DIREC))) == -1){ /* don't attempt to change directory flag */
- fprintf(stderr,"%-16s",strlwr(ffblk.ff_name));
- printf(strerror(errno));
- flag=findnext(&ffblk);
- continue;
- }
- }
- }
- if(change == 'y')
- cprintf("%-12s %-4s %-4s",strlwr(ffblk.ff_name),oldatt,newatt);
- else
- cprintf("%-12s %-4s",strlwr(ffblk.ff_name),oldatt);
- if(NewAttribute == OldAttribute && change == 'y')
- cputs(" Unchanged\r\n");
- else
- cputs("\r\n");
- flag=findnext(&ffblk);
- }
- }
-
- void help(void)
- {
- cputs("Att v1.0 ■ (c) 1989 Tony Tortorelli\r\n"
- "\r\n Usage:"
- "\r\n Att [d:][path][+-hsra /d] filename"
- "\r\n"
- "\r\n h Hidden s System"
- "\r\n r Read Only a Archive"
- "\r\n /d Include directories\r\n");
- exit(0);
- }
-